package com.example.component.Window;

import com.example.component.Window.listeners.HomeWindowListerers;
import com.example.login.ILoggedInUserDetails;
import com.example.login.ILoginService;
import com.example.service.IService;
import com.example.service.ServiceManager;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
public class HomeWindow extends Window{

	private FunFusionMenuBar myMenuBar;
	
	public HomeWindow(){
	}
	
	public HomeWindow(String title){
		super(title);
	}

	public void initWindow() {
		verifyIfAlreadyLoggedIn();
	}

	private void verifyIfAlreadyLoggedIn() {
		ILoggedInUserDetails userDetails = (ILoggedInUserDetails) this.getApplication().getUser();
		if(userDetails == null || userDetails.validateLoginStatus() == false){
			((ILoginService)ServiceManager.getInstance().getService(IService.LOGINSERVICE)).showLoginDialog(this.getApplication());
		}
		showHomePage();
	}

	private void showHomePage() {
		VerticalLayout mainLayout = new VerticalLayout();
		mainLayout.setSizeFull();
		this.setContent(mainLayout);
						
		myMenuBar = new FunFusionMenuBar();		
		myMenuBar.setWidth("100%");
		myMenuBar.addListener(new HomeWindowListerers(this.getApplication()));
		mainLayout.addComponent(myMenuBar);
	}
}
